package api.Cuisines;

import com.alibaba.fastjson2.JSON;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Map;

@WebServlet({"/api/cuisines","/api/cuisines/*"})
public class GetCuisines extends HttpServlet {
    private final ImplUseCuisines implUseCuisines = new ImplUseCuisines();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.getWriter().write(implUseCuisines.getAllCuisines());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
        Map<String, Object> body = JSON.parseObject((String) req.getAttribute("body"));
        String uri = req.getRequestURI();
        if(uri.equals("/api/cuisines/id"))implUseCuisines.getCuisines(body.get("id").toString());
    }
}
